<?php
namespace app\common\tool\profit_sharing;

class StstemMultiple extends Multiple {
	public function share($order) {
		$system = config('wechat.system');
	    $receivers = [
	        [
	            'type'              => 'MERCHANT_ID',
	            'receiver_account'  => $system['sub_mch_id'],
	            'amount'            => $order['commission'] * 100,
	            'description'       => '商户收益'
	        ]
	    ];
	    $incomeLog = [];
	    $incomeLogTypeEnum = loadEnum('IncomeLogType');
	    $incomeLogTypeOptions = $incomeLogTypeEnum->get_options();

	    $type = $incomeLogTypeEnum->code2key('xitongshouru');
	    $incomeLog[] = [
	        'uid'    => 0,
	        'oid'    => $order['id'],
	        'type'   => $type,
	        'fee'    => $order['commission'],
	        'remark' => $incomeLogTypeOptions[$type]
	    ];
	    $store = loadModel('tysj\\Store')->find($order['sid']);
	    if(empty($store)) {
	        $this->error('店铺不存在');
	    }
	    $incomeLog[] = [
	        'uid'    => $store['uid'],
	        'oid'    => $order['id'],
	        'type'   => $type,
	        'fee'    => $order['total_fee'] - $order['commission'],
	        'remark' => $incomeLogTypeOptions[$type]
	    ];
	    return $this->multiple($order, $receivers, $incomeLog);
	}
}
